#ifndef _NAND_SPI_H
#define _NAND_SPI_H
#include "stdint.h"

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C"
{
#endif

    /*spi mode enum*/
    typedef enum
    {
        NAND_SPI_MODE = 0,
        NAND_QPI_READ_MODE,
        NAND_QPI_WRITE_MODE,
    } nand_spi_type;

    /*cs enum*/

#define NAND_CS_LOW 0
#define NAND_CS_HIGH 1

    /*init spi interface*/
    void nand_spi_init(void);

    /*chip select control*/
    void nand_spi_cs(uint8_t vol);

    /*switch to spi or qpi*/
    void nand_spi_mode_spi(void);
    void nand_spi_mode_qpi_out(void);
    void nand_spi_mode_qpi_in(void);

    /*read 1 bype*/
    uint8_t nand_spi_rb(void);

    /*write 1 bype*/
    void nand_spi_wb(uint8_t wdata);

    /*read n bytes*/
    uint8_t nand_spi_read(uint8_t *prd, uint16_t len);

    /*write n bytes*/
    uint8_t nand_spi_write(const uint8_t *pwd, uint16_t len);

    /*read n bytes*/
    uint8_t nand_qpi_read(uint8_t *prd, uint16_t len);

    /*write n bytes*/
    uint8_t nand_qpi_write(const uint8_t *pwd, uint16_t len);

#ifdef __cplusplus
}
#endif

#endif
